package com.asseco.mio.core.model;


import org.appfuse.model.BaseObject;

import javax.persistence.*;
import org.appfuse.model.Role;
import org.hibernate.annotations.GenericGenerator;

@Entity @Table(name="cpauthorization")
public class CPAuthorization extends BaseObject {
       
    private String id;
    private Role role;
    private Item item;
    private String code;

    @Column(name="code", length=50)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    // START SNIPPET: id
     @Id
    @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid")
    @Column(length = 40)
    public String getId() {
        return id;
    }
    // END SNIPET: id

    public void setId(String id) {
        this.id = id;
    }
@ManyToOne
    @JoinColumn(name="role_id")
    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }
@ManyToOne
    @JoinColumn(name="item_id")
    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }


    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CPAuthorization authorization = (CPAuthorization) o;

        if (role != null ? !role.equals(authorization.role) : authorization.role != null) return false;
        if (item != null ? !item.equals(authorization.item) : authorization.item != null) return false;
        if (code != null ? !code.equals(authorization.code) : authorization.code != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (role != null ? role.hashCode() : 0);
        result = 31 * result + (item != null ? item.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "authorization{" +
                "id=" + id +
                ", role='" + role + '\'' +
                ", item='" + item + '\'' +
                ", code='" + code + '\'' +
                '}';
    }
}
